#include "intfield.h"
#include <qplugin.h>
#include <QSpinBox>

IntField::IntField()
{
}

QWidget *IntField::createDelegate(const QVariantMap &properties)
{
    QSpinBox *edit = new QSpinBox();

    if (properties.contains("min"))
        edit->setMinimum(properties["min"].toInt());

    if (properties.contains("max"))
        edit->setMaximum(properties["max"].toInt());

    if (properties.contains("step"))
        edit->setSingleStep(properties["step"].toInt());

    return edit;
}

void IntField::setEditable(QWidget *delegate, bool editable)
{
    QSpinBox *edit = (QSpinBox *)delegate;
    edit->setReadOnly(!editable);
}

QVariant IntField::data(QWidget *delegate) const
{
    QSpinBox *edit = (QSpinBox *)delegate;
    return edit->value();
}

void IntField::setData(QWidget *delegate, const QVariant &data)
{
    QSpinBox *edit = (QSpinBox *)delegate;
    edit->setValue(data.toInt());
}

void IntField::clear(QWidget *delegate)
{
    QSpinBox *edit = (QSpinBox *)delegate;
    edit->clear();
}

Q_EXPORT_PLUGIN2(int-field, IntField)
